package com.wwj.admin.wwj.controller;

import com.github.pagehelper.Page;
import com.wwj.core.wawa.entity.WaWaMachine;
import com.wwj.core.wawa.service.IWaWaMachineService;
import com.wwj.framework.utils.Page2EasyUiData;
import com.wwj.framework.utils.ReturnData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Auser on 2017/11/10.
 */
@Controller
@RequestMapping("/wwj/monitor")
public class MonitorController {

    private final String INDEX = "/admin/wwj/monitor";

    @Resource
    private IWaWaMachineService waWaMachineService;

    @RequestMapping(value={"","/","/index"})
    public String index()throws Exception{
        return INDEX;
    }

    @RequestMapping("/listData.json")
    @ResponseBody
    public ReturnData list(String search,int offset,int limit)throws Exception{
        Map<String, Object> params = new HashMap<String, Object>();
        if(null != params) params.put("search",search);
        Page<WaWaMachine> page = waWaMachineService.findByPage(params, offset, limit);
        return new ReturnData().success(Page2EasyUiData.format(page));
    }

    @RequestMapping("/change")
    @ResponseBody
    public ReturnData change(WaWaMachine waWaMachine)throws Exception{
        waWaMachineService.updateMachine(waWaMachine);
        return new ReturnData().success("ok");
    }
}
